<?php
namespace MyModel;
use MyBase\BaseModel;
class CookbookModel extends BaseModel{
	/**
	 * [cookbookDel $id可能是单个Id，也可能是个数组]
	 * @return [type] [description]
	 */
	public function cookbookDel($id){
		$where = array();
		if(is_numeric($id)){
			$where['cookbook_id'] = array('EQ',$id);
		}
		if(is_array($id)){
			$where['cookbook_id'] = array('IN',$id);
		}
		return $this->where($where)->delete();
	}

	/**
	 * [cookbookForbidden 禁用菜谱]
	 * @param  [int | Array] $id [需要禁用的菜谱的id]
	 */
	public function cookbookForbidden($id){
		$where = array();
		if(is_numeric($id)){
			$where['cookbook_id'] = array('EQ',$id);
		}
		if(is_array($id)){
			$where['cookbook_id'] = array('IN',$id);
		}		
		$update['cookbook_status'] = 'N';
		return $this->where($where)->save($update);
	}
	/**
	 * [cookbookForbidden 恢复菜谱]
	 * @param  [int | Array] $id [需要禁用的菜谱的id]
	 */
	public function cookbookRecover($id){
		$where = array();
		if(is_numeric($id)){
			$where['cookbook_id'] = array('EQ',$id);
		}
		if(is_array($id)){
			$where['cookbook_id'] = array('IN',$id);
		}		
		$update['cookbook_status'] = 'Y';
		return $this->where($where)->save($update);
	}
	/**
	 * [getCookbookInfoById 根据id获取菜谱信息]
	 * @param  [type] $id [description]
	 * @return [type]     [description]
	 */
	public function getCookbookInfoById($id){
		$where = array();
		if(!is_numeric($id)){
			return false;
		}
		$where['cookbook_id'] = array('EQ',$id);
		return $this->where($where)->find();
	}

	/**
	 * 更新菜谱
	 */
	public function updateCookbookById($id,$data){
		$where = array();
		if(!is_numeric($id)){
			return false;
		}
		$where['cookbook_id'] = array('EQ',$id);
		return $this->where($where)->save($data);
	}
	/**
	 * 根据条件获取
	 */
	public function getCookbookByCondition($where,$columns,$order,$limit=8,$page=1){
		return $this->where($where)->field($columns)->order($order)->limit($limit)->page($page)->select();
	} 
}